unit sci.module;

interface

uses
  Classes, SysUtils, Windows, sci.functions, sci.log, math.global;

procedure LoadModule(path: string);

implementation


procedure LoadModule(path: string);
var
  h: THandle;
  i: integer;
  sl: TStringList;
  fg: function: TStringList;
begin
  log(mathLog, 'Loading module ''' + path + '''...');
  if not FileExists(path) then raise Exception.Create('No such module: ' + path);
  h := LoadLibrary(PChar(path));
  fg := GetProcAddress(h, 'GetFuncs');
  if fg = nil then raise Exception.Create('Invalid moudule(getFuncs not found)');
  sl := fg;
  for i := 0 to sl.Count - 1 do
  begin
    inc(funcsCount);
    with funcs[funcsCount] do
    begin
      name := sl[i];
      handler := GetProcAddress(h, PWideChar('_' + sl[i]));
    end;
  end;
end;

end.
